package com.jsgt.greekfire.ui.coin

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.fhx.core.base.BaseFragment
import com.fhx.core.utils.ToastUtils
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.coin.adapter.CoinAdapter
import com.jsgt.greekfire.ui.trading.fragment.VolumeFragment
import com.scwang.smartrefresh.header.MaterialHeader
import kotlinx.android.synthetic.main.fragment_coin_list.*

private const val ARG_PARAM1 = "param1"

class CoinListFragment : BaseFragment() {
    private var param1: String? = null
    var carList = mutableListOf<CoinBean>()
    private val coinAdapter by lazy {

        var bean1 = CoinBean("越努力越幸运","99%","44648",
            "2686.25","1000-18,561","6.91","1","2")
        var bean2 = CoinBean("越努力","56%","1234",
            "684.648","984-69489","3.54","1","1")
        var bean3 = CoinBean("越幸运","-23%","984846",
            "494.65465","654-9846","6541.6549","2","1")
        carList.add(bean1)
        carList.add(bean2)
        carList.add(bean3)

        CoinAdapter(context!!,R.layout.item_coin_list)
    }
    override fun getLayoutId(): Int = R.layout.fragment_coin_list

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
        }
    }


    companion object {
        @JvmStatic
        fun newInstance(param1: String) =
            CoinListFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                }
            }
    }

    override fun main() {
        rvCoin.layoutManager = LinearLayoutManager(context)
        rvCoin.adapter = coinAdapter
        coinAdapter?.setNewData(carList)
        refreshCoin.setRefreshHeader(MaterialHeader(context));
        refreshCoin.setOnRefreshListener {
        }
        coinAdapter.setOnItemClickListener { adapter, view, position ->
                ToastUtils.show(activity!!,coinAdapter.data.get(position).name)
        }


    }

}